/**
 * @author : cyb1010
 * @date   : 2024-12-04 11:12:56
 * @file   : graph.cpp
 */
#include "graph.h"
#include <bits/stdc++.h>
using namespace std;
#define fo(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
#define fi first
#define se second
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) int(v.size())
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
void ckmx(int &x, int y) { x < y && (x = y); }
void ckmn(int &x, int y) { x > y && (x = y); }
const int N = 210;
int __, n, fa[N], fe[N], dis[N][N], cnt[N];
int g[N][N], e[N][N], D[N];
void dfs(int p) {
    D[p] = NumberOfRoads(), fe[p] = LastRoad(), g[p][max(fe[p], 0)] = fa[p];
    for (int i = 1; i <= D[p]; i++) {
        if (i == fe[p]) continue;
        Move(i, 2);
        if (Color() > 1) {
            if (Color() == 3) e[p][i] = -1;
            Move(LastRoad(), Color());
        } else {
            fa[++n] = p, dfs(g[p][i] = n);
            Move(fe[g[p][i]], 3);
        }
    }
}
void solve(int p, int x) {
    for (int i = 1; i <= D[p]; i++)
        if (i != fe[p] && g[p][i])
            Move(i, p / x % 3 + 1), solve(g[p][i], x),
                Move(fe[g[p][i]], g[p][i] / x % 3 + 1);
    for (int i = 1; i <= D[p]; i++)
        if (!g[p][i] && e[p][i] >= 0) {
            Move(i, p / x % 3 + 1);
            e[p][i] = e[p][i] * 3 + Color() - 1;
            Move(LastRoad(), Color());
        }
}
void Inspect(int R) {
    dfs(++n);
    for (int i = 81; i; i /= 3) solve(1, i);
    fill(&dis[1][1], &dis[n + 1][1], 201);
    for (int i = 1; i <= n; i++) dis[i][i] = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= D[i]; j++)
            dis[i][g[i][j]] = dis[i][max(e[i][j], 0)] =
                dis[max(e[i][j], 0)][i] = 1;
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++) ckmn(dis[i][j], dis[i][k] + dis[k][j]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) cnt[dis[i][j]]++;
    for (int i = 1; i <= R; i++) Answer(i, cnt[i] / 2);
}
